﻿@{
    ViewBag.Title = "Nservice Bus Examples";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb" style="margin-top: 10px;">
    <li><a href="/Home/Home">Home</a></li>
    <li><a href="/NServiceBus/Introduction">Nservice Bus</a></li>
    <li class="active">Example</li>
</ol>

            
            <div id="introduction">
                <h1 class="text-left">Example Of NServiceBus</h1>
            </div>
            <div id="ExampleofNServiceBus">
                <h3><strong>Example</strong></h3>
                <ul>
                    <li>we are going to create a very simple ordering system that will send messages from a client to a server. The ordering system includes three projects: Client, Server, and Messages,Subscriber</li>

                </ul>
                <ol start="1">
                    <li>
                        First you have Creating The Message Project<br /><p>First Lets add class Library Project call "Message"</p><br /><img src="E:/M.Sc(I.T.) Project Training/Data/Images/addMC.png" class="img-thumbnail" height=100% width=100% /><br />
                        <br />The Messages Project is Container of Message Defination.It is Shared Between Client and Server.So both Sides agree on the typed Message on Description.
                    </li>
                    <br />Install the 'NServiceBusInterfaces' NuGet package for this new project.
                    <br />Add Command with Property.Implement the PlaceMessage command in 'PlaceMessage.cs'.
                    <br />
                    <br />
                    <img src="~/Images/NServiceBus/pm.png" class="img-thumbnail" height=100% width=100% />
                    <br />In this Property there two variables Id which is type of Guid and Msg is type of string.
                    <br /> Next is Create event that is Notify Id type of Guid to Subscriber.Implementing the MessagePlaced with IEvent.
                    <br />
                    <br />
                    <img src="~/Images/NServiceBus/mevent.png" class="img-thumbnail" height=100% width=100% />
                    <br />
                    <li>
                        Second you have to Creating The Client Project that will send Message to NServiceBus endpoint.
                        <p>Add Class Library Project call "Client" in Same Solution.</p>
                        Add Reference Using Manage NuGet Package.Three Package Install.
                        <br /><br /><img src="~/Images/NServiceBus/pkg.png" class="img-thumbnail" height=100% width=100% />
                        <br /><strong>NServiceBus Package</strong><br />NServiceBus package comes will all the necessary dependencies to start using NServiceBus immediately.
                        <br /><strong>NServiceBusInterface</strong><br />The Interfaces For NserviceBus Implementation.
                        <br /><strong>NserviceBus.Host</strong><br />If you're implementing some back-end message processing, you don't have to write your own host process any more. Just reference NServiceBus.Host.exe from your message handler assembly and write a single class which inherits from IConfigureThisEndpoint, specifying whether you want server or client behavior and you're done.
                        <p>
                            The package installation process adds references to NServiceBus assemblies and creates several template files in the Client project.
                            For Example EndPointConfig.cs File is Use to Configure the Project endpoints,and by default Configuration is set to Server.
                        </p>
                        <br /><img src="~/Images/NServiceBus/clientendpoint.png" class="img-thumbnail" height=100% width=100% /><br />
                    </li>
                    <li>Send Message</li>
                    <p>Add new Class Library call "Client".In Client class Library Add Reference to Message.Create Class call "SendMessage.cs".</p>
                    <br />
                    <img src="~/Images/NServiceBus/sendm.png" class="img-thumbnail" height=100% width=100% />
                    <br />
                    <strong>IWantToRunWhenBusStartsAndStops (Interface)</strong>Implementers will be invoked when the endpoint starts up.there are two Methods.
                    <br />
                    <strong>Start :-</strong>Method Called at Startup.
                    <br />
                    <strong>Stop :-</strong>Method Called on Shoutdown.
                    <br />The Bus Property is filled via Dependency Injection.The Class invoked at Startup automatically and uses its reference Bus.send() that is send Message to Server(MyPublisher).
                    <br />In app.config file of Client to add Assembly MessageEndPointMapping Because command is Send only Endpoint For Processing.
                    <br />
                    <img src="~/Images/NServiceBus/clientappconfig.png" class="img-thumbnail" height=100% width=100% />
                    <br />In app.config
                    <br />
                    <strong>MessageForwardingInCaseOfFaultConfig</strong>is Use When a message fails, NSB will retry the message and then forward it to another queue so it can continue processing.
                    <br />
                    <strong>UnicastBusConfig </strong>it is simply tells what type of messages you want to Send.
                    <br />
                    <strong>AuditConfig</strong>Configure Section for Auditing Feature.
                    <br />
                    <strong>MassageEndPointMappings</strong>MessageEndpointMapping section when adding mapping we set Endpoint Name and it's same as namespace of EndpointConfig class in MyPublisher Project.
                    <br />

                    <li>
                        Next we Have Creating Server(MyPublisher).
                        <br />Add new Class Library call "Mypublisher".In MyPublisher Create Message Processing Server.<br />For Server Side to Understand and Interpret the Message Content add Reference to Message in MyPublisher(Server).
                        <br /><br /><img src="~/Images/NServiceBus/handlepub.png" class="img-thumbnail" height=100% width=100% />
                        <br />This class automatically Invoked when PlaceMessage arrives and handle the Message with Implementing IHandleMessage and Print out to the console "Msg and Id" Property of the PlacedMessage.Bus.Publish is to notify with Id multiple Subscribers of Particular event.
                        <br />In MyPublisher EndpointConfig.cs file to implement the AsA_Publisher marker Interface that will configure the endpoint with a Publisher Profile.
                    </li>
                    <li>
                        Now Last we have Creating Subscriber<br />In Subscriber endpoint that subscribe and Handle the "Message" Event.Install Package NServiceBus.Host using Nuget and also add reference to "Message" in Subscriber.
                        In Subscriber Handle Message with Implementing IHandleMessage.
                        <br /><br /><img src="~/Images/NServiceBus/subhandler.png" class="img-thumbnail" height=100% width=100% />
                        <br />Handle The Message With Property Id of event.
                        <br />For Host will Auto Subscribe to Message we need to add the message Publisher.In subscriber we will add MessageEndPointMapping in app.config file.
                        <br /><br /><img src="~/Images/NServiceBus/subappconfig.png" class="img-thumbnail" height=100% width=100% />
                    </li>
                    <li>
                        Run Application<br />The Solution all Working Together we will run client,Mypublisher,Subscriber Project.<br />Right Click On Project Solution and select "StartUpProjects".In that to select Multiple Startup Project and set the client,MyPublisher,Subscriber action to Start.After you can run the solution Three Console Window Open.
                        <br /><br /><img src="~/Images/NServiceBus/run.png" class="img-thumbnail" height=100% width=100% />
                        <br />In Above Top of console is Client,Right of console is MyPublisher(Server),Left of the console is Subscriber.<br />Hit Enter in Client Console that is Send Message to Publisher placeMessage with id and Message and publisher publish this id with eventmessage.if any Subscriber is in it notify with eventmessage.
                    </li>
                    <br />
                    <br />
                    <img src="~/Images/NServiceBus/output.png" class="img-thumbnail" height=100% width=100% />
                    <br />Publish/Subscribe Messeging is Working.
                </ol>
            </div>

 